package com.webguard.outlierdetection.service.impl;
import com.webguard.outlierdetection.service.EmailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

import java.util.Random;

@Service
public class EmailImpl implements EmailService {

    @Autowired
    private JavaMailSender mailSender;

    public void sendSimpleEmail(String email, String subject, String text) {
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom("3286723626@qq.com"); // 发件人邮箱
        message.setTo(email); // 收件人邮箱
        message.setSubject(subject); // 邮件主题
        message.setText(text); // 邮件内容
        mailSender.send(message);
    }

    public Integer sendCode(String email) {
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom("3286723626@qq.com"); // 发件人邮箱
        message.setTo(email); // 收件人邮箱
        message.setSubject("验证码"); // 邮件主题
        Random random = new Random();
        int code = random.nextInt(900000) + 100000;
        message.setText(""+code); // 验证码
        mailSender.send(message);
        return code;
    }
}